package com.guo.hui.controller;

import com.alibaba.fastjson.JSONObject;
import com.guo.hui.entity.MyAccount;
import com.guo.hui.service.MyAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.List;

/**
 * @ClassName MyAccountController
 * @Description TODO
 * @Author zhengguohui
 * @Date 2018/8/9 10:54
 */

@Controller
@Api(description = "简易记账系统接口",tags = "MyAccountController")
public class MyAccountController {

    @Autowired
    private MyAccountService accountService;

//    @ApiIgnore
//    @RequestMapping(value = "/", method = RequestMethod.GET)
//    public String index() {
//        return "account";
//    }

    @ApiOperation(value = "获取收支列表",notes = "获取收支列表")
    @ApiImplicitParam(name = "param", value = "{\n" +
            "\"inoutCode\":\"1\"\n" +
            "}", required = true, dataType = "JsonObject")
    @ResponseBody
    @RequestMapping(value = "/getAccountList", method = RequestMethod.POST)
    public String getAccountList(@RequestBody String param) {
        JSONObject object = JSONObject.parseObject(param);
        List<MyAccount> list = accountService.getAccountList(object);
        return JSONObject.toJSONString(list);
    }

    @ApiOperation(value = "保存收支数据", notes = "保存收支数据")
    @ApiImplicitParam(name = "param", value = "{\n" +
            "\"inoutCode\":\"1\",\n" +
            "\"usercode\":\"000001\",\n" +
            "\"username\":\"guohui\",\n" +
            "\"money\":100.5,\n" +
            "\"remark\":\"日常消费\"\n" +
            "}", required = true, dataType = "JsonObject")
    @ResponseBody
    @RequestMapping(value = "/saveAccount", method = RequestMethod.POST)
    public void saveAccount(@RequestBody String param) {
        JSONObject object = JSONObject.parseObject(param);
        accountService.saveAccount(object);
    }

    @ApiIgnore
    @ResponseBody
    @RequestMapping(value = "/updateAccount")
    public void updateAccount(@RequestBody String param) {
        JSONObject object = JSONObject.parseObject(param);
    }
}
